package com.xjrsoft.module.customer.erp_model.goodsCategoryManage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.dto.ErpGoodscategoryDto;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.dto.SaveErpGoodscategoryFormDataDto;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.vo.ErpGoodscategoryVo;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.vo.ErpGoodscategoryListVo;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.dto.ErpGoodscategoryListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import com.xjrsoft.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.entity.ErpGoodscategory;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.vo.ErpGoodscategoryVo;
import com.xjrsoft.module.customer.erp_model.goodsCategoryManage.service.IErpGoodscategoryService;

/**
 *  控制器
 *
 * @author pp
 * @since 2021-09-23
 */
@RestController
@AllArgsConstructor
@RequestMapping("/goodscategorymanage")
@Api(value = "商品分类", tags = "商品分类接口")
public class ErpGoodscategoryController {


	private final IErpGoodscategoryService erpGoodscategoryService;


	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入erpGoodscategory")
	public Response<ErpGoodscategoryVo> getFormData(@PathVariable String id) {
		// 主表数据
		ErpGoodscategory erpGoodscategory = erpGoodscategoryService.getById(id);
		return Response.ok(BeanUtil.copy(erpGoodscategory, ErpGoodscategoryVo.class));
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入erpGoodscategory")
	public Response<PageOutput<ErpGoodscategoryListVo>> getPageList(ErpGoodscategoryListDto listDto) {
		IPage<ErpGoodscategory> page = erpGoodscategoryService.getPageList(listDto);
		List<ErpGoodscategoryListVo> records = BeanUtil.copyList(page.getRecords(), ErpGoodscategoryListVo.class);
		// 转换列表数据
		DataTransUtil.transListShowData(records);
		// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入erpGoodscategory")
	public Response save(@RequestBody SaveErpGoodscategoryFormDataDto formDto) {
		ErpGoodscategoryDto erpGoodscategoryDto = formDto.getErpGoodscategoryDto();
		ErpGoodscategory erpGoodscategory = BeanUtil.copy(erpGoodscategoryDto, ErpGoodscategory.class);
		String dataId = erpGoodscategoryService.addErpGoodscategory(erpGoodscategory);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入erpGoodscategory")
	public Response update(@PathVariable String id, @RequestBody SaveErpGoodscategoryFormDataDto formDto) {
		ErpGoodscategoryDto erpGoodscategoryDto = formDto.getErpGoodscategoryDto();
		ErpGoodscategory erpGoodscategory = BeanUtil.copy(erpGoodscategoryDto, ErpGoodscategory.class);
		return Response.status(erpGoodscategoryService.updateErpGoodscategory(id, erpGoodscategory));
	}


	
	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(erpGoodscategoryService.removeByIds(Func.toStrList(ids)));
	}

	
}
